package interfaceImp;

import java.rmi.RemoteException;
import java.util.ArrayList;

import server.ServerStarter;
import server.VectorCell;

import interfaces.CurrentTurn;

public class CurrentTurnImpl implements CurrentTurn {

	int currentTurn=1;
	int current=0;
	ArrayList<Integer> left =new ArrayList<Integer>();
	public CurrentTurnImpl()
	{
		left.add(1);
		left.add(2);
		left.add(3);
		left.add(4);
	}
	@Override
	public synchronized void setCurrentTurn(int id,int caller) throws RemoteException {
		currentTurn =id;
		if(caller!=0)
		{
		ServerStarter.getClock().list.get(caller-1).add(new VectorCell(caller, SERVIC_NAME + "_set"));
		}
		
	}

	@Override
	public synchronized int getCuttentTurn(int caller) throws RemoteException {
		
		if(caller!=0)
		{
		ServerStarter.getClock().list.get(caller-1).add(new VectorCell(caller, SERVIC_NAME + "_get"));
		}
		return currentTurn;
		
	}
	@Override
	public void nextTurn(int caller) throws RemoteException {
		int ite = left.size();
		currentTurn=left.get(current);
		if(caller!=0)
		{
		ServerStarter.getClock().list.get(caller-1).add(new VectorCell(caller, SERVIC_NAME + "_next"));
		}
		
		
	}

}
